package common;

/**
 * @description:
 * @author: yangxuan10
 * @create: 2024-04-23 11:16
 **/
public class TreeNode {

    public int val;

    public TreeNode left;

    public TreeNode right;

    public TreeNode(int val) {
        this.val = val;
    }

    public TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }


    /***
     * <pre>
     * 树生成方式一：
     *          1
     *        2   3
     *
     * 树生成方式二：
     *           1
     *        2     3
     *      4  5  6  7
     * </pre>
     * @return
     */
    public static TreeNode generateTree(int mode){
        if (mode == 1) {
            return new TreeNode(1,new TreeNode(2),new TreeNode(3));
        } else if (mode == 2) {
            TreeNode treeNode1 = new TreeNode(2,new TreeNode(4),new TreeNode(5));
            TreeNode treeNode2 = new TreeNode(3,new TreeNode(6),new TreeNode(7));
            return new TreeNode(1, treeNode1, treeNode2);
        }
        throw new NullPointerException();
    }

}